from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC
import time


class Base:
    def __init__(self, driver):
        self.driver = driver

    def open_url(self, url):
        self.driver.get(url)

    def find_selement(self, loc):
        WebDriverWait(self.driver, 20, 0.5).until(EC.visibility_of_element_located(loc))
        return self.driver.find_element(*loc)

    def click(self, loc):
        self.find_selement(loc).click()

    def send_keys(self, loc, txt):
        self.find_selement(loc).send_keys(txt)

    def switch_fream(self, n):
        self.driver.switch_to.frame(n)

    def action_le(self, loc):
        ActionChains(self.driver).move_to_element(loc).perform()

    def new_switch(self):
        self.driver.switch_to.window(self.driver.window_handles[-1])

    def clear(self, loc):
        self.find_selement(loc).clear()

    def switch_file(self):
        self.driver.switch_to.default_content()
